/**
 * @file lv_watch_tabview.h
 *
 */

#ifndef LV_WATCH_TABVIEW_H
#define LV_WATCH_TABVIEW_H

#ifdef __cplusplus
extern "C" {
#endif

/*********************
 *      INCLUDES
 *********************/
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lvgl.h"
#include "lv_watch_conf.h"
#else
#include "../../../lvgl/lvgl.h"
#include "../../../lv_watch_conf.h"
#endif

#if USE_LV_WATCH_TABVIEW != 0

/*Testing of dependencies*/
#if LV_USE_PAGE == 0
#error "lv_watch_tabview: lv_page is required. Enable it in lv_conf.h (USE_LV_PAGE  1) "
#endif

/*********************
 *      DEFINES
 *********************/

/**********************
 *      TYPEDEFS
 **********************/

/* parametes: pointer to a tabview object, tab_id
 * return: LV_RES_INV: to prevent the loading of the tab;  LV_RES_OK: if everything is fine*/
typedef lv_res_t (*lv_watch_tabview_action_t)(lv_obj_t *, uint16_t);
typedef void (*lv_watch_tabview_cb_t)(void *);

/*Data of tab*/
typedef struct
{
    /*Ext. of ancestor*/
    /*New data for this type */
    lv_obj_t * content;   /*A rectangle to show the current tab*/
    lv_point_t point_last;
    lv_point_t point_start;
    lv_point_t point_now;
    lv_coord_t hor_drag_start;
    lv_coord_t ver_drag_start;
    uint16_t tab_cur;
    uint16_t tab_cnt;
    uint16_t anim_time;
    uint8_t slide_enable :1;    /*1: enable horizontal sliding by touch pad*/
    uint8_t draging :1;
    uint8_t drag_hor :1;
    uint8_t element_click_en :1;
    uint8_t page_hor_edge_flash_en :1;
    uint8_t hor_sliding_loop_en :1;
    uint8_t is_drag_up :1;
    uint8_t is_drag_right :1;
    lv_watch_tabview_cb_t slide_up_press_lost_cb;
    lv_watch_tabview_cb_t slide_down_press_lost_cb;
    lv_watch_tabview_cb_t long_press_cb;
    lv_watch_tabview_cb_t slide_up_pressing_cb;
    lv_watch_tabview_cb_t slide_down_pressing_cb;
    lv_watch_tabview_cb_t slide_left_press_lost_cb;
    lv_watch_tabview_cb_t slide_right_press_lost_cb;
    lv_obj_t * leds_content;
    lv_obj_t ** leds;
    uint8_t show_leds_en; /*one bit for one tab*/
} lv_watch_tabview_ext_t;

typedef struct
{
    uint8_t sliding_up_en :1;
    uint8_t sliding_down_en :1;
    uint8_t sliding_left_en :1;
    uint8_t sliding_right_en :1;
} lv_watch_tabview_element_free_ptr_client_t;

/**********************
 * GLOBAL PROTOTYPES
 **********************/


/**
 * Create a Tab view object
 * @param par pointer to an object, it will be the parent of the new tab
 * @param copy pointer to a tab object, if not NULL then the new object will be copied from it
 * @return pointer to the created tab
 */
lv_obj_t * lv_watch_tabview_create(lv_obj_t * par);

/**
 * Delete all children of the scrl object, without deleting scrl child.
 * @param obj pointer to an object
 */
void lv_watch_tabview_clean(lv_obj_t *obj);

/*======================
 * Add/remove functions
 *=====================*/

/**
 * Add a new tab with the given name
 * @param tabview pointer to Tab view object where to ass the new tab
 * @return pointer to the created page object (lv_page). You can create your content here
 */
lv_obj_t * lv_watch_tabview_add_tab(lv_obj_t * tabview);

void lv_watch_tabview_add_element_with_special(lv_obj_t * element, lv_watch_tabview_element_free_ptr_client_t * attribute);
void lv_watch_tabview_add_element(lv_obj_t * element);

/*=====================
 * Setter functions
 *====================*/

/**
 * Set a new tab
 * @param tabview pointer to Tab view object
 * @param id index of a tab to load
 * @param anim_en true: set with sliding animation; false: set immediately
 */
void lv_watch_tabview_set_tab_act(lv_obj_t * tabview, uint16_t id, bool anim_en);

/**
 * Set an action to call when a tab is loaded (Good to create content only if required)
 * lv_tabview_get_act() still gives the current (old) tab (to remove content from here)
 * @param tabview pointer to a tabview object
 * @param action pointer to a function to call when a tab is loaded
 */
//void lv_watch_tabview_set_tab_load_action(lv_obj_t *tabview, lv_tabview_action_t action);

/**
 * Enable horizontal sliding with touch pad
 * @param tabview pointer to Tab view object
 * @param en true: enable sliding; false: disable sliding
 */
void lv_watch_tabview_set_sliding(lv_obj_t * tabview, bool en);

/**
 * Set the animation time of tab view when a new tab is loaded
 * @param tabview pointer to Tab view object
 * @param anim_time time of animation in milliseconds
 */
void lv_watch_tabview_set_anim_time(lv_obj_t * tabview, uint16_t anim_time);

/**
 * Enable the edge flash effect. (Show an arc when the an edge is reached)
 * @param tileview pointer to a tabview
 * @param en true or false to enable/disable end flash
 */
void lv_watch_tabview_set_edge_flash(lv_obj_t * tabview, bool en);

void lv_watch_tabview_set_slide_up_press_lost_cb(const lv_obj_t * tabview, void (*cb)(lv_obj_t *));
void lv_watch_tabview_set_slide_down_press_lost_cb(const lv_obj_t * tabview, void (*cb)(lv_obj_t *));
void lv_watch_tabview_set_long_press_cb(const lv_obj_t * tabview, void (*cb)(lv_obj_t *));
void lv_watch_tabview_set_slide_up_pressing_cb(const lv_obj_t * tabview, void (*cb)(lv_obj_t *));
void lv_watch_tabview_set_slide_down_pressing_cb(const lv_obj_t * tabview, void (*cb)(lv_obj_t *));
lv_obj_t ** lv_watch_tabview_set_show_leds_en(lv_obj_t * tabview, uint8_t show_leds_en);
void lv_watch_tabview_set_slide_left_press_lost_cb(const lv_obj_t * tabview, void (*cb)(lv_obj_t *));
void lv_watch_tabview_set_slide_right_press_lost_cb(const lv_obj_t * tabview, void (*cb)(lv_obj_t *));

/*=====================
 * Getter functions
 *====================*/

/**
 * Get the index of the currently active tab
 * @param tabview pointer to Tab view object
 * @return the active tab index
 */
uint16_t lv_watch_tabview_get_tab_act(const lv_obj_t * tabview);

/**
 * Get the number of tabs
 * @param tabview pointer to Tab view object
 * @return tab count
 */
uint16_t lv_watch_tabview_get_tab_count(const lv_obj_t * tabview);
/**
 * Get the page (content area) of a tab
 * @param tabview pointer to Tab view object
 * @param id index of the tab (>= 0)
 * @return pointer to page (lv_page) object
 */
lv_obj_t * lv_watch_tabview_get_tab(const lv_obj_t * tabview, uint16_t id);

/**
 * Get horizontal sliding is enabled or not
 * @param tabview pointer to Tab view object
 * @return true: enable sliding; false: disable sliding
 */
bool lv_watch_tabview_get_sliding(const lv_obj_t * tabview);

lv_res_t lv_watch_tabview_signal(lv_obj_t * tabview, lv_signal_t sign, void * param);

lv_obj_t * lv_watch_tabview_get_from_obj(lv_obj_t *obj);

/**********************
 *      MACROS
 **********************/

#endif  /*USE_LV_WATCH_TABVIEW*/

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif  /*LV_WATCH_TABVIEW_H*/
